export const getArraytList =(array:any, num:any)=> {
    const result = [];
    const cnt = array.length % num == 0 ? array.length / num : (Math.floor(array.length / num) + 1);
    for (let i = 0; i < cnt; i++) {
        let item = []
        for (let j = 0; j < num; j++) {
            let index = i * num + j;
            if (index < array.length) {
                if (i % 2 == 0) {
                    item.push(array[index])
                } else {
                    item.unshift(array[index])
                }
            }
        }
        result.push(item)
}
return result;
}
export const flattenArrayList =(arr:any)=> {
  return arr.reduce((acc:any, val:any) => Array.isArray(val) ? acc.concat(flattenArrayList(val)) : acc.concat(val), []);
}
export const uniqArray =(arr:any,key:any)=> {
    if(!arr && !key){
        return []
    }
    const obj = {};
    const list = [];
    arr.forEach((item:any) => {
    obj[item[key]] ? "" : (obj[item[key]] = true && list.push(item));
    })
    return list
}


  
  

export const getPageList =(total:any,limit=2000)=> {
    if(total>0){
        let pageStr = (total/limit).toFixed(3)
        let totalPage =0
        let page1 = pageStr.split('.')[0]
        let page2 = pageStr.split('.')[1]
        let pages =[]
        if(Number(page2)>0){
            totalPage = Number(page1)+1
          }else{
            totalPage = Number(page1)
          }
        for(let i=1;i<=totalPage;i++){
            pages.push({page:i,limit:limit})
        }
       return pages
    }else{
        return []
    }
}
    